using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Atom.Data.ManagerObjects;
using Atom.Data.BusinessObjects;
using Atom.Data.Base;

namespace Atom.Data.UnitTests
{
	[TestFixture]
    public partial class DSummaryInfoTests : UnitTestbase
    {
        [SetUp]
        public void SetUp()
        {
            manager = managerFactory.GetDSummaryInfoManager();
            manager.Session.BeginTransaction();
        }

        [TearDown]
        public void TearDown()
        {
            manager.Session.RollbackTransaction();
            manager.Dispose();
        }
        
        protected Atom.Data.ManagerObjects.IDSummaryInfoManager manager;
		
		protected Atom.Data.BusinessObjects.DSummaryInfo CreateNewDSummaryInfo()
		{
			Atom.Data.BusinessObjects.DSummaryInfo entity = new Atom.Data.BusinessObjects.DSummaryInfo();
			
			// You may need to maually enter this key if there is a constraint violation.
			entity.Id = "Test T";
			
			entity.Codeno = "Tes";
			entity.Spellno = "Test T";
			entity.Customno = "Test Test Test T";
			entity.Strokeno = "Test T";
			entity.Chargeitem = "Test Test ";
			entity.Subjectid = "Tes";
			entity.Summary = "Test Tes";
			entity.Unit = "Test Test Test Tes";
			entity.Unitprice = 22;
			entity.Fixedprice = 17;
			entity.Type = 38;
			entity.Reportitem = "Test Test Test Test Test Te";
			entity.Checkitem = "Te";
			entity.Explain1 = "Test Test ";
			entity.Explain2 = "Test Test ";
			entity.Explain3 = "Test Test ";
			entity.Especialcheck = "Test Te";
			entity.Rolltype = 76;
			entity.Clinicinvoiceid = "Test T";
			entity.Inhosinvoiceid = "Test Test";
			entity.Stopflag = 79;
			entity.Medicarepricefixing = 91;
			entity.Attitemid = "Test Tes";
			entity.Percent = 39;
			entity.Lisitem = "Test Tes";
			entity.Createoperator = "Test Tes";
			entity.Createdate = System.DateTime.Now;
			entity.Editoperator = "Test Tes";
			entity.Editdate = System.DateTime.Now;
			entity.Accessionmodality = "Test T";
			
			return entity;
		}
		protected Atom.Data.BusinessObjects.DSummaryInfo GetFirstDSummaryInfo()
        {
            IList<Atom.Data.BusinessObjects.DSummaryInfo> entityList = manager.GetAll(1);
            if (entityList.Count == 0)
                Assert.Fail("All tables must have at least one row for unit tests to succeed.");
            return entityList[0];
        }
		
		[Test]
        public void Create()
        {
            try
            {
				Atom.Data.BusinessObjects.DSummaryInfo entity = CreateNewDSummaryInfo();
				
                object result = manager.Save(entity);

                Assert.IsNotNull(result);
            }
            catch(Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Read()
        {
            try
            {
                Atom.Data.BusinessObjects.DSummaryInfo entityA = CreateNewDSummaryInfo();
				manager.Save(entityA);

                Atom.Data.BusinessObjects.DSummaryInfo entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA, entityB);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
		[Test]
		public void Update()
        {
            try
            {
                Atom.Data.BusinessObjects.DSummaryInfo entityA = GetFirstDSummaryInfo();
				
				entityA.Codeno = "Test Test Tes";
				
				manager.Update(entityA);

                Atom.Data.BusinessObjects.DSummaryInfo entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA.Codeno, entityB.Codeno);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Delete()
        {
            try
            {
                Atom.Data.BusinessObjects.DSummaryInfo entity = GetFirstDSummaryInfo();
				
                manager.Delete(entity);

                entity = manager.GetById(entity.Id);
                Assert.IsNull(entity);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
	}
}

